<template>
    <div class="page-order-result white-bg">
        <div class="main">
            <div class="success-box">
                <div class="icon green-color">&#xe63d;</div>
                <div class="text-normal">订单支付成功</div>
            </div>
            <div class="btn-box text-normal">
                <div class="btn btn-mobile btn-block btn-grey grey-border" @click="onClickIndex">返回首页</div>
                <div class="btn btn-mobile btn-block btn-red" @click="onClickOrder">查看订单</div>
            </div>
        </div>
    </div>
</template>

<script lang="ts">
import {
    api,
} from '@/lib/api';
import { Component, Vue } from 'vue-property-decorator';
import { ROUTE_NAME } from '@/lib/constant';
import store from '@/store';

@Component({
    name: 'OrderResult',
})
export default class OrderResult extends Vue {
    public get type() {
        return this.$route.params.type;
    }
    /** 订单id */
    public get orderId() {
        return this.$route.params.orderId;
    }

    /**
     * 点击回到首页
     */
    public onClickIndex() {
        // api.navigateTo({
        //     url: '/pages/index/main',
        // });
        api.launch({
            name: ROUTE_NAME.HOME_INDEX,
        });
    }
    /**
     * 点击查看订单
     */
    public async onClickOrder() {
        // api.navigateTo({
        //     url: '/pages/order_detail/main',
        //     query: {
        //         order_id: this.orderId,
        //     },
        // });

        if (this.type === 'pkg') {
            api.push({
                name: ROUTE_NAME.ORDER_DETAIL,
                params: {
                    orderId: this.orderId + '',
                },
            });
        } else if (this.type === 'product') {
            const rdata = await store.dispatch('order/getCombinedOrderDetail', {
                orderId: this.orderId,
            });

            if (rdata.status === 0) {
                const orderId = rdata.data.order_id;
                if (orderId.length > 1) {
                    api.push({
                        name: ROUTE_NAME.ORDER_LIST,
                    });
                } else {
                    api.push({
                        name: ROUTE_NAME.ORDER_DETAIL,
                        params: {
                            orderId: orderId[0] + '',
                        },
                    });
                }
            }
        }
    }
}
</script>

<style lang="less">
@import "../../lib/style/mixins.less";

.page-order-result {
    .main {
        .success-box {
            padding: 63px 0;
            text-align: center;
            .icon {
                margin-bottom: 10px;
                font-size: 56px;
            }
        }
        .btn-box {
            display: flex;
            justify-content: space-around;
            .btn {
                width: 122px;
                height: 36px;
                line-height: 36px;
                text-align: center;
                border-radius: 14rpx;
            }
        }
    }
}

</style>
